<html>
<head>
    <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>

<form class="layui-form" action="" style="margin-top: 20px;margin-right: 30px;">

    <input type="hidden" name="coupon_id" value="{$data.coupon_id}">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="1" title="优惠券" {if condition="$data.type == 1"}checked{/if}>
            <input type="radio" name="type" value="2" title="代金券"  {if condition="$data.type == 2"}checked{/if}>
            <input type="radio" name="type" value="3" title="兑换券"  {if condition="$data.type == 3"}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">说明</label>
        <div class="layui-input-block">
            <input type="text" name="description" id="description" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.description}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" id="address" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.address}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商店</label>
        <div class="layui-input-block">
            <input type="text" name="supermarket" id="supermarket" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.supermarket}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">面值</label>
        <div class="layui-input-block">
            <input type="text" name="value" id="value" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.value}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">使用条件</label>
        <div class="layui-input-block">
            <input type="text" name="condition" id="condition" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.condition}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">数量</label>
        <div class="layui-input-block">
            <input type="text" name="num" id="num" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.num}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">有效期类型</label>
        <div class="layui-input-block">
            <input type="radio" name="expired_type" value="1" title="开始时间固定" {if condition="$data.expired_type == 1"}checked{/if}>
            <input type="radio" name="expired_type" value="2" title="开始时间不固定"  {if condition="$data.expired_type == 2"}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-block">
            <input type="date" name="start_time" id="start_time" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.start_time}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">有效天数</label>
        <div class="layui-input-block">
            <input type="number" name="expired_date" id="expired_date" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.expired_date}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业ID</label>
        <div class="layui-input-block">
            <input type="text" name="uid" id="uid" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.uid}">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
        </div>
    </div>
</form>


<script src="/js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script src="/layui/layui.js"></script>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        //监听提交
        form.on('submit(formDemo)', function(data){
            var data = data.field;

            $.post("/ops/coupon/edit", data, function (res) {
                var res = JSON.parse(res);
                if(res.errno==0){
                    layer.msg('操作成功')
                }

                window.parent.location.reload();
            });
            return false;
        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/ops/company/upload', //上传接口
            field: 'image'
            ,done: function(res){
                // var data = JSON.parse(res)
                var data = res;
                if(data.errno == 0){
                    var str = "<div id=\"test1\"><img src='"+data.data.url+"' style='width: 120px;'>"
                    str += "<input type='hidden' name='image' value='"+data.data.url+"'/></div>"

                    $('#img').html(str);
                }else {
                    alert(data.errmsg);
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
    });

</script>


</body>
</html>

